package com.example.templateapp.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.templateapp.R
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder

class UserCardAdapter(val context: Context) : RecyclerView.Adapter<RecyclerViewHolder>() {

    private val dataList = mutableListOf<String>()


    override fun getItemViewType(position: Int): Int {
        return if (position == 1) 0 else 1
    }

    fun refresh(data: Collection<String>) {
        dataList.clear()
        dataList.addAll(data)
        notifyDataSetChanged()
    }

    fun add(info: String) {
        dataList.add(info)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
        val layoutInflater = LayoutInflater.from(context)
        return if (viewType == 0) {
            VipViewHolder(layoutInflater, parent)
        } else {
            NormalUserViewHolder(layoutInflater, parent)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    private fun getItem(position: Int): String {
        return dataList[position]
    }

    override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {

    }

    class NormalUserViewHolder(layoutInflater: LayoutInflater, parent: ViewGroup) :
        RecyclerViewHolder(
            layoutInflater.inflate(R.layout.adapter_user_card, parent, false)
        )

    class VipViewHolder(layoutInflater: LayoutInflater, parent: ViewGroup) :
        RecyclerViewHolder(
            layoutInflater.inflate(R.layout.adapter_vip_card, parent, false)
        )
}